package org.saratogaschools.edd.firefighter.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class AddFireView extends Composite {
	
	public interface Presenter {

		void searchForAddresses(String address);
		
	}
	@UiField
	Button searchButton;
	@UiField
	TextBox addressBox;
	
	
	private Presenter presenter;

	private static AddFireViewUiBinder uiBinder = GWT
			.create(AddFireViewUiBinder.class);

	interface AddFireViewUiBinder extends UiBinder<Widget, AddFireView> {
	}

	public AddFireView() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@UiHandler("searchButton")
	void onSearchButtonCLicked(ClickEvent evt) {
		searchButton.setEnabled(false);
		addressBox.setEnabled(false);
		String address = addressBox.getText();
		if (address.isEmpty()) {
			searchButton.setEnabled(true);
			addressBox.setEnabled(true);
		}
		else {
			presenter.searchForAddresses(address);
		}
	}

}
